/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view.promo;

import java.awt.Color;
import java.awt.Component;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableRowSorter;
import main.ServicesList;
import model.promo.Promo;
import utility.Constants;
import utility.NameValueList;
import utility.StringUtils;
import utility.com.CheckboxTableRenderer;
import utility.com.ComponentUtils;
import utility.typeSafe.EnumUtils;
import utility.typeSafe.PromoJenis;
import view.RekapTemplate;

/**
 *
 * @author jay
 */
public class PromoListFrm extends RekapTemplate {

    private static final int COL_NO = 0;
    private static final int COL_NAMA = 1;
    private static final int COL_START_DATE = 2;
    private static final int COL_END_DATE = 3;
    private static final int COL_JENIS = 4;
    private static final int COL_WHOIS = 5;
    private static final int COL_NOTES = 6;
    private static final int COL_STATUS = 7;
    
    private List<Promo> promoList;
    private PromoTM tableModel;
    
    private TableRowSorter<PromoTM> sorter;
    private Object oldValue, newValue;
    private ItemListener comboboxListener = new ComboboxListener();
    
    private List<NameValueList> promoJenis = EnumUtils.enumToNameValueList(PromoJenis.class);
    
    public PromoListFrm() {
        initComponents();
    }

    class ComboboxListener implements ItemListener {
        @Override
        public void itemStateChanged(ItemEvent e) {
            if(e.getStateChange()==ItemEvent.SELECTED) {
                loadData();
            }
        }
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jSplitPane1 = new javax.swing.JSplitPane();
        jPanel1 = new javax.swing.JPanel();
        txtNama = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        cmbJenisPromo = new javax.swing.JComboBox();
        jLabel7 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        chkMember = new javax.swing.JCheckBox();
        chkNonMember = new javax.swing.JCheckBox();
        jPanel3 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        dtpStartDateSampai = new com.toedter.calendar.JDateChooser();
        dtpStartDateDari = new com.toedter.calendar.JDateChooser();
        jLabel1 = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        dtpEndDateSampai = new com.toedter.calendar.JDateChooser();
        dtpEndDateDari = new com.toedter.calendar.JDateChooser();
        jLabel5 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        grid = new javax.swing.JTable();
        jToolBar1 = new javax.swing.JToolBar();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        btnReset = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jSplitPane1.setDividerLocation(0);
        jSplitPane1.setDividerSize(10);
        jSplitPane1.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
        jSplitPane1.setLastDividerLocation(100);
        jSplitPane1.setOneTouchExpandable(true);

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel1.setPreferredSize(new java.awt.Dimension(14, 50));

        txtNama.setName("txtNama"); // NOI18N

        jLabel6.setText("Nama :");

        cmbJenisPromo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        cmbJenisPromo.setName("cmbJenisPromo"); // NOI18N

        jLabel7.setText("Jenis Promo :");

        jLabel10.setText("Berlaku Untuk :");

        chkMember.setText("Member");
        chkMember.setName("chkMember"); // NOI18N

        chkNonMember.setText("Non Member");
        chkNonMember.setName("chkNonMember"); // NOI18N
        chkNonMember.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                chkNonMemberActionPerformed(evt);
            }
        });

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Tanggal Mulai"));
        jPanel3.setToolTipText("");

        jLabel2.setText("Sampai :");

        dtpStartDateSampai.setName("dtpStartDateSampai"); // NOI18N

        dtpStartDateDari.setName("dtpStartDateDari"); // NOI18N

        jLabel1.setText("Dari :");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(dtpStartDateSampai, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(dtpStartDateDari, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addGap(0, 10, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(dtpStartDateDari, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(dtpStartDateSampai, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2)))
        );

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Tanggal Akhir"));
        jPanel4.setToolTipText("");

        jLabel4.setText("Sampai :");

        dtpEndDateSampai.setName("dtpEndDateSampai"); // NOI18N

        dtpEndDateDari.setName("dtpEndDateDari"); // NOI18N

        jLabel5.setText("Dari :");

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel5, javax.swing.GroupLayout.Alignment.TRAILING))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(dtpEndDateSampai, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(dtpEndDateDari, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                .addGap(0, 10, Short.MAX_VALUE)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel5)
                    .addComponent(dtpEndDateDari, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(dtpEndDateSampai, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4)))
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel10)
                    .addComponent(jLabel7)
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtNama)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(chkMember)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(chkNonMember))
                            .addComponent(cmbJenisPromo, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(0, 124, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel10)
                            .addComponent(chkMember)
                            .addComponent(chkNonMember))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(cmbJenisPromo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel7))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtNama, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel6))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jSplitPane1.setTopComponent(jPanel1);

        grid.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        jScrollPane1.setViewportView(grid);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 765, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 257, Short.MAX_VALUE)
        );

        jSplitPane1.setRightComponent(jPanel2);

        jToolBar1.setFloatable(false);
        jToolBar1.setRollover(true);
        jToolBar1.setMaximumSize(new java.awt.Dimension(32767, 20));
        jToolBar1.setSize(this.getWidth(), 50);

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/edit_add.png"))); // NOI18N
        jButton1.setText("Tambah");
        jButton1.setFocusable(false);
        jButton1.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        jButton1.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jToolBar1.add(jButton1);

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/edit.png"))); // NOI18N
        jButton2.setText("Edit");
        jButton2.setFocusable(false);
        jButton2.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        jButton2.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        jToolBar1.add(jButton2);

        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/edit_remove.png"))); // NOI18N
        jButton3.setText("Hapus");
        jButton3.setFocusable(false);
        jButton3.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        jButton3.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(jButton3);

        jButton5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/reload.png"))); // NOI18N
        jButton5.setText("Load");
        jButton5.setFocusable(false);
        jButton5.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        jButton5.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });
        jToolBar1.add(jButton5);

        btnReset.setText("Reset");
        btnReset.setFocusable(false);
        btnReset.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btnReset.setName("btnReset"); // NOI18N
        btnReset.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnReset.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnResetActionPerformed(evt);
            }
        });
        jToolBar1.add(btnReset);

        jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/print.png"))); // NOI18N
        jButton4.setText("Print");
        jButton4.setFocusable(false);
        jButton4.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        jButton4.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });
        jToolBar1.add(jButton4);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jSplitPane1)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 269, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void chkNonMemberActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chkNonMemberActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_chkNonMemberActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        loadData();
    }//GEN-LAST:event_jButton5ActionPerformed

    private void btnResetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnResetActionPerformed
        initFilter();
    }//GEN-LAST:event_btnResetActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        insertGrid();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        updateGrid();
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        String ade = "abc;defg;hijk";
        String[] parts = ade.split(";");
        System.out.println(parts[1]);
        System.out.println(parts[2]);
    }//GEN-LAST:event_jButton4ActionPerformed

    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnReset;
    private javax.swing.JCheckBox chkMember;
    private javax.swing.JCheckBox chkNonMember;
    private javax.swing.JComboBox cmbJenisPromo;
    private com.toedter.calendar.JDateChooser dtpEndDateDari;
    private com.toedter.calendar.JDateChooser dtpEndDateSampai;
    private com.toedter.calendar.JDateChooser dtpStartDateDari;
    private com.toedter.calendar.JDateChooser dtpStartDateSampai;
    private javax.swing.JTable grid;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSplitPane jSplitPane1;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JTextField txtNama;
    // End of variables declaration//GEN-END:variables

    @Override
    public void execute(boolean withVisible, int id) {
        promoList = new ArrayList<>();
        initGrid();
        promoJenis.add(0, new NameValueList("ALL", "All"));
        cmbJenisPromo.setModel(ComponentUtils.getDefaultComboBoxModel(promoJenis));
        initFilter();
        if (withVisible) { setVisible(true); }
    }

    @Override
    protected void initGrid() {
        
        tableModel = new PromoTM(promoList);
        grid.setModel(tableModel);
        
        final TableCellRenderer header = grid.getTableHeader().getDefaultRenderer();
        DefaultTableCellRenderer rightCR = new DefaultTableCellRenderer();
        DefaultTableCellRenderer centerCR = new DefaultTableCellRenderer();
        rightCR.setHorizontalAlignment(SwingConstants.RIGHT);
        
        CheckboxTableRenderer cbRenderer = new CheckboxTableRenderer();
        cbRenderer.setHorizontalAlignment(SwingConstants.CENTER);
        grid.getColumnModel().getColumn(COL_STATUS).setCellRenderer(cbRenderer);
                     
        grid.getColumnModel().getColumn(COL_NO).setCellRenderer(rightCR);
        grid.getColumnModel().getColumn(COL_NO).setMaxWidth(40);
        grid.getColumnModel().getColumn(COL_NO).setMinWidth(40);
                
        grid.getColumnModel().getColumn(COL_NAMA).setMaxWidth(200);
        grid.getColumnModel().getColumn(COL_NAMA).setMinWidth(200);
        grid.getColumnModel().getColumn(COL_START_DATE).setMaxWidth(90);
        grid.getColumnModel().getColumn(COL_START_DATE).setMinWidth(90);
        grid.getColumnModel().getColumn(COL_END_DATE).setMaxWidth(90);
        grid.getColumnModel().getColumn(COL_END_DATE).setMinWidth(90);
        
        grid.getColumnModel().getColumn(COL_JENIS).setMaxWidth(90);
        grid.getColumnModel().getColumn(COL_JENIS).setMinWidth(90);
        
        //grid.getColumnModel().getColumn(COL_WHOIS).setMaxWidth(120);
        grid.getColumnModel().getColumn(COL_NOTES).setMaxWidth(200);
        grid.getColumnModel().getColumn(COL_NOTES).setMinWidth(200);
        
        grid.getColumnModel().getColumn(COL_STATUS).setMaxWidth(30);
        grid.getColumnModel().getColumn(COL_STATUS).setMinWidth(30);
        
        
        grid.getTableHeader().setDefaultRenderer(new TableCellRenderer() {

            @Override
            public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
                JLabel lbl = (JLabel) header.getTableCellRendererComponent(table, 
                      value, isSelected, hasFocus, row, column);
                lbl.setBorder(BorderFactory.createEmptyBorder(5,1,5,1));  
                switch (column) {
                    case COL_NO: lbl.setHorizontalAlignment(SwingConstants.RIGHT); break;
                    case COL_STATUS: lbl.setHorizontalAlignment(SwingConstants.CENTER); break;
                    default: lbl.setHorizontalAlignment(SwingConstants.LEFT); break;   
                }
                
                if (isSelected) {
                    lbl.setForeground(Color.red);
                    lbl.setBackground(Color.lightGray);
                } else {
                    lbl.setForeground(Color.WHITE);
                    lbl.setBackground(Color.DARK_GRAY);
                }
                return lbl;
            }
            
        });

        sorter = new TableRowSorter<>(tableModel);
        grid.setRowSorter(sorter);
        grid.setGridColor(Color.LIGHT_GRAY);
    }

    @Override
    protected void initFilter() {
        
        cmbJenisPromo.removeItemListener(comboboxListener);
        txtNama.setText("");
        dtpStartDateDari.setDate(null);
        dtpStartDateSampai.setDate(null);
        dtpEndDateDari.setDate(null);
        dtpEndDateSampai.setDate(null);
        cmbJenisPromo.setSelectedIndex(0);
        cmbJenisPromo.addItemListener(comboboxListener);
    }

    @Override
    protected void loadData() {
        if(promoList!=null) {
            promoList = ServicesList.getPromoService().getPromo(0, 100000, getFilter());
            initGrid();
        }
//        tableModel.clear();
//        promoList = ServicesList.getPromoService().getPromo(0, 100000, getFilter());
//        tableModel.add(promoList);
    }

    @Override
    protected void updateGrid() {
        int row = grid.getSelectedRow();
        if (row > -1) {
            if(promoList.get(row) != null) {
                new PromoFrm().execute(promoList.get(row).getId());
                Promo updatedData = ServicesList.getPromoService().getPromo(promoList.get(row).getId());
                tableModel.set(row, updatedData);
            }
        }
    }

    @Override
    protected void insertGrid() {
        int id = new PromoFrm().execute(0);
        if (id>0) {
            Promo insertedData = ServicesList.getPromoService().getPromo(id);
            tableModel.add(insertedData);
        }
    }
    
    public Map<NameValueList, Object> getFilter(){
        Map<NameValueList, Object> params = new HashMap<>();
        if(!"".equals(txtNama.getText())) { 
            params.put(new NameValueList("promo.promoName", Constants.OPERATOR_LIKE), "%"+txtNama.getText()+"%"); }

        if(dtpStartDateDari.getDate() != null) { 
            params.put(new NameValueList("promo.startDate", Constants.OPERATOR_GTE), StringUtils.truncDate(dtpStartDateDari.getDate()));
        }
        
        if(dtpStartDateSampai.getDate() != null) { 
            params.put(new NameValueList("promo.startDate", Constants.OPERATOR_LTE), StringUtils.truncDate(dtpStartDateSampai.getDate()));
        }
        
        if(dtpEndDateDari.getDate() != null) { 
            params.put(new NameValueList("promo.endDate", Constants.OPERATOR_GTE), StringUtils.truncDate(dtpEndDateDari.getDate()));
        }
        
        if(dtpEndDateSampai.getDate() != null) { 
            params.put(new NameValueList("promo.endDate", Constants.OPERATOR_LTE), StringUtils.truncDate(dtpEndDateSampai.getDate()));
        }
       
        String tag = ((NameValueList) cmbJenisPromo.getSelectedItem()).getKey();
        if (!"ALL".equals(tag)) {
             params.put(new NameValueList("promo.jenis", Constants.OPERATOR_EQUAL), tag); }
         
        
//        String whois = "";
//        if(chkMember.isSelected()) { whois = whois.concat("1"); }
//        else { whois = whois.concat("0"); }
//        
//        if(chkNonMember.isSelected()) { whois = whois.concat("1"); }
//        else { whois = whois.concat("0"); }
//        
//        params.put(new NameValueList("promo.whois", Constants.OPERATOR_EQUAL), whois); 
        
        
        params.put(new NameValueList(null, Constants.OPERATOR_ORDERBY), "promo.promoName"); 
         
        return params;
    }
    
    private void setTableLookStyle() {
        
    }
}
